package www;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Creared with IntelliJ IDEA.
 * Description:扑克牌
 * User:yxd
 * Date:2022-01-03
 * Time:23:38
 */
class MyPoker{
    private String suit;//花色
    private int rank;//数字

    public MyPoker(String suit, int rank) {
        this.suit = suit;
        this.rank = rank;
    }

    @Override
    public String toString() {
        return "[ " + this.suit + ":" + rank + " ]";
    }
}

public class Pu {
    private  static final String[] suits = {"♥","♠","♣","♦"};//所有花色
//买一副新牌
    public static List<MyPoker> buyCard(){
        List<MyPoker> list = new ArrayList<>();
        for (int i = 0; i < 4; i++) {//花色
            for (int j = 1; j <= 13; j++) {//数字
                MyPoker myPoker = new MyPoker(suits[i],j);//每一张扑克牌
                list.add(myPoker);//放入类型中
            }
        }
        return list;
    }
    public static void swap(List<MyPoker> list,int x,int y){//交换x和y位置的牌通过get和set方法
        MyPoker tmp = list.get(x);
        list.set(x,list.get(y));
        list.set(y,tmp);
    }
    public static void shift(List<MyPoker> list){
        for(int i = list.size() - 1;i > 0;i --){
            Random random = new Random();
            int b = random.nextInt(i);//i以内的随机一张牌
            swap(list,i,b);
        }

    }

    public static void main(String[] args) {
        List<MyPoker> list = buyCard();
        System.out.println("发牌："+ list);
        shift(list);
        System.out.println("洗牌：" + list);
        ArrayList<List<MyPoker>> poker = new ArrayList<>();
        ArrayList<MyPoker> poker1 = new ArrayList<>();
        ArrayList<MyPoker> poker2 = new ArrayList<>();
        ArrayList<MyPoker> poker3 = new ArrayList<>();
        poker.add(poker1);
        poker.add(poker2);
        poker.add(poker3);
        //每个人接5张牌  三个人
        for(int i = 0;i < 3;i ++){
            for(int j = 0;j < 3;j ++){
                poker.get(j).add(list.remove(0));//每次发的都是第一张牌并且不再有这张牌
            }
        }
        System.out.println("第1个人的牌:" + poker1);
        System.out.println("第2个人的牌:" +poker2);
        System.out.println("第3个人的牌:" +poker3);
        System.out.println("剩下的牌:" + list);
        //炸金花


    }
}
